$(document).ready(function(){
$('#group_button').click(function() {
	var group_id = $('select[name=group_id]').val();
	if (group_id == 0) {
		alert('请选择一个用户!');
	} else {
		window.location = '/user/group/' + group_id;
	}
});

$('#group_join').submit(function() {
	var group_id = $('input[name=group_id]').val();
	var user_id = $('select[name=user_id]').val();
	var group_role = $('input[name=group_role]:checked').val();
	if (user_id == 0 || user_id == '') {
		alert('请选择用户');
		return false;
	}
	if (group_id == 0 || group_id == '') {
		alert('数据出错了');
		return false;
	}

	$.post('/user/group_join', $('#group_join').serialize(), function(data){
			if (data.r == 'succ') {
				alert('操作成功');
				window.location.reload();
			} else {
				alert('操作失败' +  "\n>" +  data.msg.join("\n>"));
			}
	}, 'json');
	return false;
});

$('#member li a').click(function() {
	var id = $(this).attr('user_id');
	if (confirm('确定要删除?')) {
		$.get('/user/group_out/'+$(this).attr('user_id'), {}, function(data){
			if(data.r == 'succ') {
				alert('操作成功');
				window.location.reload();
			} else {
				alert('操作失败');
			}	
		}, 'json');
	}
});

});
